/*******************************************************************************
 * Copyright (c) 2017 fortiss GmbH
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Ben Schneider
 *      - initial implementation and documentation
 *******************************************************************************/

#ifndef CSERVICECALLMANAGER_H
#define CSERVICECALLMANAGER_H

#include "forte/esfb.h"
#include "forte/extevhan.h"
#include "forte/arch/forte_thread.h"

#include <vector>

class FORTE_TRIGGER_SERVICE_CLIENT;

class CServiceCallManager : public CExternalEventHandler,
                            public RegisterExternalEventHandler<CServiceCallManager>,
                            private CThread {
  public:
    explicit CServiceCallManager(CDeviceExecution &paDeviceExecution);
    ~CServiceCallManager() override;

  private:
    std::vector<FORTE_TRIGGER_SERVICE_CLIENT *> m_callerVector;
    std::vector<FORTE_TRIGGER_SERVICE_CLIENT *> m_connectVector;

  public:
    void enableHandler() override;
    void disableHandler() override;

    void startChain(CEventSourceFB *paECStartF);
    void queueServiceCall(FORTE_TRIGGER_SERVICE_CLIENT *pa_serviceClientPtr);
    void queueConnectWait(FORTE_TRIGGER_SERVICE_CLIENT *pa_serviceClientPtr);

  protected:
    void run() override;
};

#endif
